package com.ruoyi.eqmonitor.controller;

import java.util.List;

import com.ruoyi.eqmonitor.domain.OptDeviceMonitorConfig;
import com.ruoyi.eqmonitor.service.IOptDeviceMonitorConfigService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import java.util.Arrays;
import java.util.Date;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.security.utils.SecurityUtils;

import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 设备监测预警配置
 * @author ruoyi
 * @date 2022-11-26
 */
@RestController
@RequestMapping("/config")
public class OptDeviceMonitorConfigController extends BaseController{

    @Autowired
    private IOptDeviceMonitorConfigService optDeviceMonitorConfigService;

    /**
     * 设备监测预警配置列表
     */
    @ApiOperation("设备监测预警配置列表")
    @GetMapping("/list")
    public TableDataInfo<?> list(OptDeviceMonitorConfig optDeviceMonitorConfig){
        startPage();
        List<OptDeviceMonitorConfig> list = optDeviceMonitorConfigService.selectOptDeviceMonitorConfigList(optDeviceMonitorConfig);
        return getDataTable(list);
    }

    /**
     * 设备监测预警配置明细
     */
    @ApiOperation("设备监测预警配置明细")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id){
        return AjaxResult.success(optDeviceMonitorConfigService.selectOptDeviceMonitorConfigById(id));
    }

    /**
     * 新增设备监测预警配置
     */
    @ApiOperation("新增设备监测预警配置")
    @Log(title = "设备监测预警配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OptDeviceMonitorConfig optDeviceMonitorConfig){
        return toAjax(optDeviceMonitorConfigService.saveDeviceMonitorConfig(optDeviceMonitorConfig));
    }

    /**
     * 修改设备监测预警配置
     */
    @ApiOperation("修改设备监测预警配置")
    @PutMapping
    public AjaxResult edit(@RequestBody OptDeviceMonitorConfig optDeviceMonitorConfig){
        return toAjax(optDeviceMonitorConfigService.updateDeviceMonitorConfigById(optDeviceMonitorConfig));
    }

    /**
     * 变更设备监测预警配置状态
     */
    @ApiOperation("变更设备监测预警配置状态")
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody OptDeviceMonitorConfig optDeviceMonitorConfig){
        return toAjax(optDeviceMonitorConfigService.changeStatus(optDeviceMonitorConfig));
    }

    /**
     * 删除变更设备监测预警配置
     */
    @ApiOperation("删除变更设备监测预警配置")
    @Log(title = "设备监测预警配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        return toAjax(optDeviceMonitorConfigService.removeDeviceMonitorConfigByIds(Arrays.asList(ids)));
    }

    /**
     * 导出设备监测预警配置列表
     */
    @ApiOperation("导出设备监测预警配置列表")
    @Log(title = "设备监测预警配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OptDeviceMonitorConfig optDeviceMonitorConfig){
        List<OptDeviceMonitorConfig> list = optDeviceMonitorConfigService.selectOptDeviceMonitorConfigList(optDeviceMonitorConfig);
        ExcelUtil<OptDeviceMonitorConfig> util = new ExcelUtil<OptDeviceMonitorConfig>(OptDeviceMonitorConfig.class);
        util.exportExcel(response, list, "设备监测预警配置数据");
    }

}
